package com.itheima.hashsetdemo.hashstudent;

import java.util.HashSet;

public class Test {
    public static void main(String[] args) {
        HashSet<Student> hs = new HashSet<Student>();
        Student s1 = new Student("张三", 18);
        Student s2 = new Student("李四", 20);
        Student s3 = new Student("王舞", 16);
        Student s4 = new Student("张三", 18);

        hs.add(s1);
        hs.add(s2);
        hs.add(s3);
        hs.add(s4);
        //HashSet集合存储自定义类型元素,要想实现元素的唯一
        // 要求必须重写hashCode方法和equals方法
        for (Student h : hs) {
            System.out.println(h.getName() + h.getAge());
        }
    }

}
